<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

<script type="text/javascript">
function fetch_course(str)
{
	
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
 
xmlhttp.open("GET","getcourse.php?q="+str,true);
xmlhttp.send();
}

</script>
<?php 
$univer = $_POST['univer'];
$course = $_POST['course'];
$sname = mysql_real_escape_string($_POST['sname']);
$duration = mysql_real_escape_string($_POST['duration']);
$edetails = mysql_real_escape_string($_POST['edetails']);
$ginfo = mysql_real_escape_string($_POST['ginfo']);
$einstr = mysql_real_escape_string($_POST['einstr']);
$maincont = mysql_real_escape_string($_POST['maincont']);
$url=$_POST['url'];
$mail=$_POST['mail'];
$phone=$_POST['phone'];
$authorised = $_POST['authorised'];

if(isset($_POST['savecourse']))
{
	
	if($_GET['m']!=edit)
	{
				
			
		mysql_query("INSERT INTO scholarships(`university_id`, `course_id`,`scholarship_name`, `duration`,`details_description`, `extra_details`, `general_info`, `eligible_instruction`,`url`,`email`,`phone`,`active_status`, `created_datetime`)
						
											   VALUES('$univer','$course','$sname','$duration','$maincont','$edetails','$ginfo','$einstr','$url','$mail','$phone',
													   '$authorised',now())");	
		echo "<script>window.location='index.php?tc=add_scholarship&_s=1'</script>";
	}
	
}
if(isset($_POST['updatecourse']))

{


			
mysql_query("UPDATE scholarships  SET
			`university_id` = '$univer',
			`course_id`='$course',
			`scholarship_name`='$sname',
			`duration`='$duration',
			`details_description`='$maincont',
			`extra_details`='$edetails',
			`general_info`='$ginfo',
			`eligible_instruction`='$einstr',
			`url`='$url',
			`email`='$mail',
			`phone`='$phone',
			`active_status` ='$authorised'
			 where id='".$_POST['hid']."'")
or 
die(mysql_error());

	
	echo "<script>window.location='index.php?tc=scholarship&_s=1'</script>";
	
}
?>
<?php if($_REQUEST['_s'] == 1){ ?>
    <div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;</div>
<?php } ?>
<?php 

$ssql="select * from scholarships where id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);

if($row['active_status']=='1')
{
	
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
	
$chkdec = 'checked="checked"';
}
?>
<script language="javascript">
function validate()
{
	var no=/^[0-9.]+$/;
	var na =/^[a-zA-Z.]+$/;
	var mail=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if(document.up.sname.value=="")
	{
		alert("Scholarship Name  Missing");
		document.up.sname.focus();
		return false;
	}
	
	
	
}
</script>
<form name="up" action="#" method="post" onSubmit="return validate()">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['id'];?>" />
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">Scholarship</div>
        <div style="float:right"><a href="index.php?tc=scholarship" class="back">Manage scholarship</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="left" width="150">University</td>
    <td align="left">
    <select name="univer" id="univer" class="txtborder" style="width:350px;" onchange="return fetch_course(this.value)"  >
     <option value="0" selected="selected"></option>
    <?php 
	
	
$ads=mysql_query("select * from university where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
		
	?>
   
    <option <?php if($row['university_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['university_name']?></option>
    <?php }?>
    </select> 
    
    </td>
</tr>
<tr>
	<td align="left" width="150">Course</td>
    <td align="left">
   <select name="course" id="txtHint" style="width:350px;"  >
<?php 
	
 $ads=mysql_query("select * from course where id='".$row['course_id']."' and active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?>
      <option <?php if($row['course_id']==$tech['id']){echo "selected";}?>  value="<?php echo  $tech['id'];?>">
        <?php //echo $str;?>
         <?php echo $tech['course_name'];?>
         </option> 
         <?php }?>
   </select>
</td></tr>
<tr>
	<td align="left" width="150">Scholarship Name *</td>
    <td align="left"><input type="text" name="sname" style="width:350px;" value="<?php echo  $row['scholarship_name'];?>"  /></td>
</tr>
<!--<tr>
	<td align="left" width="150">Duration </td>
    <td align="left"><input type="text" name="duration" style="width:350px;" value="<?php echo  $row['duration'];?>"  /></td>
</tr>
<tr>
	<td align="left" width="150">Extra Details</td>
    <td align="left"><textarea type="text" name="edetails" cols="41" rows="5"><?php echo  $row['extra_details'];?></textarea></td>
</tr>
<tr>
	<td align="left" width="170">General Information</td>
    <td align="left"><textarea type="text" name="ginfo" cols="41" rows="5"><?php echo  $row['general_info'];?></textarea>  </td>
</tr>
<tr>
	<td align="left" width="150">Eligible Instruction</td>
    <td align="left"><textarea type="text" name="einstr" cols="41" rows="5"><?php echo  $row['eligible_instruction'];?></textarea>  </td>
</tr>
<tr>
	<td colspan="2" align="left" width="150">Contact Information *</td>
    
</tr>
<tr>
	<td align="left" width="150">Url</td>
    <td align="left"><input type="text" name="url" style="width:350px;" value="<?php echo  $row['url'];?>"  /></td>
</tr>
<tr>
	<td align="left" width="150">E-mail</td>
    <td align="left"><input type="text" name="mail" style="width:350px;" value="<?php echo  $row['email'];?>"  /></td>
</tr>
<tr>
	<td align="left" width="150">Phone</td>
    <td align="left"><input type="text" name="phone" style="width:350px;" value="<?php echo  $row['phone'];?>"  /></td>
</tr>
<tr>

    <td align="left" colspan="2">
    	Detailed  Description
     <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo $row['details_description'];?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
    </td>
</tr>-->

<tr>
  <td align="right" width="150">Status </td>
  <td align="left">
  <input name="authorised" type="radio" value="1" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:155px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="savecourse" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updatecourse" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
